package com.jar.exercise.多线程.volatile_test;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

public class Test {
    public volatile int inc = 0;
 
    public synchronized void increase() {
        inc++;
    }
 
    public static void main(String[] args) throws InterruptedException {
        final Test test = new Test();
        for(int i=0;i<10;i++){
            new Thread(){
                public void run() {
                    for(int j=0;j<1000;j++)
                        test.increase();
                };
            }.start();
        }
//
        while(Thread.activeCount()>1)  //保证前面的线程都执行完
            Thread.yield();
        TimeUnit.SECONDS.sleep(5);
        System.out.println(test.inc);
        System.out.println(Thread.activeCount());
        Thread.currentThread().getThreadGroup().list();
    }
}